//
//  CyToolDefine.h
//  CyLibs
//
//  Created by clyde on 12-11-29.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef CyLibs_CyToolDefine_h_2013_135935
#define CyLibs_CyToolDefine_h_2013_135935

// Debug Logging
#if 1 // Set to 1 to enable debug logging
#define CYLog(x, ...) NSLog(x, ## __VA_ARGS__);
#else
#define CYLog(x, ...)
#endif


/* 系统版本 */
#define SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

// screen size
#define kScreenHeight ([[UIScreen mainScreen] bounds].size.height)
#define kScreenWidth ([[UIScreen mainScreen] bounds].size.width)

//抑制执行选择器泄漏警告
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

// check is iphone5
#define isIphone5 (kScreenHeight == 568.0f)

// emun
#define CY_ENUM_2(_name, enum0, enum1) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##End\
}_name

#define CY_ENUM_3(_name, enum0, enum1, enum2) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##End\
}_name

#define CY_ENUM_4(_name, enum0, enum1, enum2, enum3) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##End\
}_name

#define CY_ENUM_5(_name, enum0, enum1, enum2, enum3, enum4) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##End\
}_name

#define CY_ENUM_6(_name, enum0, enum1, enum2, enum3, enum4, enum5) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##enum5,\
k##_name##End\
}_name

#define CY_ENUM_7(_name, enum0, enum1, enum2, enum3, enum4, enum5, enum6) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##enum5,\
k##_name##enum6,\
k##_name##End\
}_name

#define CY_ENUM_8(_name, enum0, enum1, enum2, enum3, enum4, enum5, enum6, enum7) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##enum5,\
k##_name##enum6,\
k##_name##enum7,\
k##_name##End\
}_name

#define CY_ENUM_9(_name, enum0, enum1, enum2, enum3, enum4, enum5, enum6, enum7, enum8) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##enum5,\
k##_name##enum6,\
k##_name##enum7,\
k##_name##enum8,\
k##_name##End\
}_name

#define CY_ENUM_10(_name, enum0, enum1, enum2, enum3, enum4, enum5, enum6, enum7, enum8, enum9) \
typedef enum\
{\
k##_name##Start = 0,\
k##_name##enum0 = 0,\
k##_name##enum1,\
k##_name##enum2,\
k##_name##enum3,\
k##_name##enum4,\
k##_name##enum5,\
k##_name##enum6,\
k##_name##enum7,\
k##_name##enum8,\
k##_name##enum9,\
k##_name##End\
}_name

// 颜色值
// rgb
#define kCyColorFromRGBA(r, g, b, a) [UIColor colorWithRed:((r) / 255.0f) green:((g) / 255.0f) blue:((b) / 255.0f) alpha:(a)]

#define kCyColorFromRGB(r, g, b) [UIColor colorWithRed:((r) / 255.0f) green:((g) / 255.0f) blue:((b) / 255.0f) alpha:(1.0f)]

// 从16进制得到颜色值 0x222222
#define kCyColorFromHexA(hex, a) [UIColor colorWithRed:(((hex & 0xff0000) >> 16) / 255.0f) green:(((hex & 0x00ff00) >> 8) / 255.0f) blue:((hex & 0x0000ff) / 255.0f) alpha:(a)]
#define kCyColorFromHex(hex) [UIColor colorWithRed:(((hex & 0xff0000) >> 16) / 255.0f) green:(((hex & 0x00ff00) >> 8) / 255.0f) blue:((hex & 0x0000ff) / 255.0f) alpha:(1.0f)]

//删除本地存储信息
#define kRemoveSaveObject(key) \
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];\
[[NSUserDefaults standardUserDefaults] synchronize]

// 本地存储信息
#define kGetUserSystemObject(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]

#define kSaveUserSystemObject(key, value) \
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize]

//自定义对象存储
#define kGetCustomObject(key, value) \
NSData *serialized = [[NSUserDefaults standardUserDefaults] objectForKey:key]; \
if(serialized){ \
value = [NSKeyedUnarchiver unarchiveObjectWithData:serialized];\
}\
else{ \
value = nil; \
}

#define kSaveCustomObject(key, value)  do{\
NSData *serialized = [NSKeyedArchiver archivedDataWithRootObject:value];\
if(serialized){ \
[[NSUserDefaults standardUserDefaults] setObject:serialized forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}\
}\
while(0)

#endif
